package com.richman.controller;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.json.JSONObject;

import com.richman.hg.HGHttp;
import com.richman.hg.HGManager;
import com.richman.isn.ISNManager;
import com.richman.ps38.PS38Http;
import com.richman.ps38.PS38Manager;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.SendData;

public class BetCentralManager {
	
	
	public HGManager hgmanager = null;
	
	public PS38Manager ps38manager = null;
	
	public ISNManager isnManager = null;
	
	//public PS38Http ps38http = new PS38Http();

	public Vector<BetAdyData> betAdyDatas = new Vector<BetAdyData>();
	
	
	public Vector<BetAdyData> specialBetAdyDatas = new Vector<BetAdyData>();
	
	public Vector<BetAdyData> specialBetLogDatas = new Vector<BetAdyData>();
	
	public Vector<BetAdyData> betLogDatas = new Vector<BetAdyData>();
	
	
	int testbettimes = 0;
	
	
	public Vector<BetDvalue> betDvalues = new Vector<BetDvalue>();
	
	
	
	private  ReadWriteLock lockebetAdyDatas = new ReentrantReadWriteLock();
	
	
	public long lastbetsuccesstime = System.currentTimeMillis();
	
	Long updateBetlogTime = System.currentTimeMillis();
	
	Long updateSpecialBetlogTime = System.currentTimeMillis();
	
	Long updateps38BetlogTime = System.currentTimeMillis();
	
	Long checkIllegalTime = System.currentTimeMillis();
	
	Long getRedcardTime = System.currentTimeMillis();
	
	Long checkSpecialIllegalTime = System.currentTimeMillis();
	
	
	
	public void bettest() {
		
		String hgHometeam = "蒙特瑞";
		String hgAwayteam = "艾特莱";
		
		String isnHometeam = "";
		String isnAwayteam = "";
		
		BetClient.isnteamsLock.readLock().lock();;
		
		for(String[] team: BetClient.isnteams) {

			if(team[0].equals(hgHometeam)) {
				isnHometeam = team[1];
			}
			
			if(team[0].equals(hgAwayteam)) {
				isnAwayteam = team[1];
			}
		}
		
		BetClient.isnteamsLock.readLock().unlock();
		
		if(testbettimes > 0) {
			return;
		}
		

//		if(!isnHometeam.equals("") && !isnAwayteam.equals("")) {
//			String res = isndobet(isnHometeam, isnAwayteam, "1", 0.99, 100,0.99);
//			
//			if(res != null) {
//
//				//System.out.println(res);
//
//				
//			}
//			
//		}
		
	}
	
	
	
	public void updateBetAdyTable() {
		BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
	}
	
	public void updateBetAdyData(BetAdyData bad) {
		
		betAdyDatas.add(bad);
		
		
		BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
		
		saveBetlistVectofile();
		
	}
	
	public void getRedcard() {
		try {
			if(System.currentTimeMillis() - getRedcardTime < 30*1000 ) {
				return;
			}
			getRedcardTime = System.currentTimeMillis();
			hgmanager.getRedCard();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

	public void updateSpecialBetAdyData(BetAdyData bad) {
		
		specialBetAdyDatas.add(bad);

		BetClient.mainWnd.updateSpecialBetAdyTable(specialBetAdyDatas);
		
		saveSpecialBetlistVectofile();
		
	}

	
	public void updateSpecialBetLogData(BetAdyData bad) {
		
		specialBetLogDatas.add(bad);

		BetClient.mainWnd.updateSpecialBetLogTable(specialBetLogDatas);
		
		saveSpecialBetlogVectofile();
		
	}
	
	
	public void updateBetLogData(BetAdyData bad) {
		
		betLogDatas.add(bad);
		
		
		BetClient.mainWnd.updateBetLogTable(betLogDatas);
		
		saveBetLogVectofile();
		
	}
	
	
	public void clearBetAdyData() {
		
		if(betAdyDatas!= null && betAdyDatas.size() != 0) {
			betAdyDatas.clear();
			
			BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
			
			saveBetlistVectofile();
		}
		
	}
	
	
	public void clearBetLogData() {
		
		if(betLogDatas!= null && betLogDatas.size() != 0) {
			betLogDatas.clear();
			
			BetClient.mainWnd.updateBetLogTable(betLogDatas);
			
			saveBetLogVectofile();
		}
		
	}
	
	
	public void clearSpecialBetAdyData() {
		if(specialBetAdyDatas!= null && specialBetAdyDatas.size() != 0) {
			specialBetAdyDatas.clear();
			
			BetClient.mainWnd.updateSpecialBetAdyTable(specialBetAdyDatas);
			
			saveSpecialBetlistVectofile();
		}
	}
	
	
	public void clearSpecialBetLogData() {
		
		if(specialBetLogDatas!= null && specialBetLogDatas.size() != 0) {
			specialBetLogDatas.clear();
			
			BetClient.mainWnd.updateSpecialBetLogTable(specialBetLogDatas);
			
			saveSpecialBetlogVectofile();
		}
		
	}
	
	
	public Vector<BetAdyData> getBetAdyData(){
		return betAdyDatas;
	}
	
	
	public Vector<BetAdyData> getBetLogData(){
		return betLogDatas;
	}
	
	
	public  boolean recoverBetlistVecfromefile(){
		
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
//			if(currentTime.get(Calendar.HOUR_OF_DAY) >= 12){
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}else{
//				currentTime.add(Calendar.DAY_OF_MONTH, -1);
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}
			
			
			//读取改目录下所有文件:
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				return true;
			}
			
			File flist[] = filefolder.listFiles();
			
			int linenum = 0;
			
			for(File f : flist){
				if(f.getName().equals("betres.data")){
//					System.out.println("fuck directory here");
//				}else{
					//System.out.println(f.getAbsolutePath());
					//
					
					
					BufferedReader freader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
					
					String str = "";
					
					linenum = 0;
					
					while ((str = freader.readLine()) != null) {
						
						
						BetAdyData bad = new BetAdyData(str);
						
						betAdyDatas.add(bad);
						
							
						}
					
					
					
					
					if(null != freader){
						freader.close();
					}
					
					
				}
				
				
				
				
			}
			
			
			BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
			
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
		
	}
	
	
	
	

	
	

	public  boolean recoverSpecialBetlistVecfromefile(){
		
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
//			if(currentTime.get(Calendar.HOUR_OF_DAY) >= 12){
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}else{
//				currentTime.add(Calendar.DAY_OF_MONTH, -1);
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}
			
			
			//读取改目录下所有文件:
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				return true;
			}
			
			File flist[] = filefolder.listFiles();
			
			int linenum = 0;
			
			for(File f : flist){
				if(f.getName().equals("specialbetres.data")){
//					System.out.println("fuck directory here");
//				}else{
					//System.out.println(f.getAbsolutePath());
					//
					
					
					BufferedReader freader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
					
					String str = "";
					
					linenum = 0;
					
					while ((str = freader.readLine()) != null) {
						
						if(str.length() < 3) {
							continue;
						}
						
						
						BetAdyData bad = new BetAdyData(str);
						
						specialBetAdyDatas.add(bad);
						
							
						}
					
					
					
					
					if(null != freader){
						freader.close();
					}
					
					
				}
				
				
				
				
			}
			
			
			BetClient.mainWnd.updateSpecialBetAdyTable(specialBetAdyDatas);
			
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
		
	}
	

	

	public  boolean recoverSpecialBetlogVecfromefile(){
		
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";

			
			
			//读取改目录下所有文件:
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				return true;
			}
			
			File flist[] = filefolder.listFiles();
			
			int linenum = 0;
			
			for(File f : flist){
				if(f.getName().equals("specialbetlog.data")){
//					System.out.println("fuck directory here");
//				}else{
					//System.out.println(f.getAbsolutePath());
					//
					
					
					BufferedReader freader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
					
					String str = "";
					
					linenum = 0;
					
					while ((str = freader.readLine()) != null) {
						
						if(str.length()<3) {
							continue;
						}
						
						
						BetAdyData bad = new BetAdyData(str);
						
						specialBetLogDatas.add(bad);
						
							
						}
					
					
					
					
					if(null != freader){
						freader.close();
					}
					
					
				}
				
				
				
				
			}
			
			
			BetClient.mainWnd.updateSpecialBetLogTable(specialBetLogDatas);
			
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
		
	}
	
	
	
	public  boolean recoverBetLogVecfromfile(){
		
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
//			if(currentTime.get(Calendar.HOUR_OF_DAY) >= 12){
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}else{
//				currentTime.add(Calendar.DAY_OF_MONTH, -1);
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}
			
			
			//读取改目录下所有文件:
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				return true;
			}
			
			File flist[] = filefolder.listFiles();
			
			int linenum = 0;
			
			for(File f : flist){
				
				
				
				if(f.getName().equals("betlog.data")){
//					System.out.println("fuck directory here");
//				}else{
					//System.out.println(f.getAbsolutePath());
					//
					
					
					BufferedReader freader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
					
					String str = "";
					
					linenum = 0;
					
					while ((str = freader.readLine()) != null) {
						
						
						BetAdyData bad = new BetAdyData(str);
						
						betLogDatas.add(bad);
						
							
						}
					
					
					
					
					if(null != freader){
						freader.close();
					}
					
					
				}
				
				
				
				
			}
			
			
			BetClient.mainWnd.updateBetLogTable(betLogDatas);
			
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public  boolean saveBetlistVectofile(){
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				filefolder.mkdir();
			}
			
//			if(currentTime.get(Calendar.HOUR_OF_DAY) >= 12){
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}else{
//				currentTime.add(Calendar.DAY_OF_MONTH, -1);
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}
			
//			filefolder = new File("betdata/" + folder + "/");
//			
//			if(!filefolder.exists()){
//				filefolder.mkdir();
//			}
			
			String filenametmp = "betres"
					+ ".data";
			
			
			
			
			
			File file = new File("betdata/" +filenametmp);
			
			if(!file.exists()){
				System.out.println("create betdata/" + filenametmp);
				
				
				
				file.createNewFile();
			}
			
			BufferedWriter fwlocal = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));
			
			
			
			
			for(int i = 0; i < betAdyDatas.size(); i++){
				
				BetAdyData item = betAdyDatas.elementAt(i);
				
				String str = item.toString();
				
				fwlocal.append(str);
				fwlocal.newLine();
				fwlocal.flush();

			}
			
			fwlocal.close();
			
			
			
			return true;
			
			
		}catch(Exception e){
			e.printStackTrace();
			
			
			
			
			return false;
		}
	}
	

	
	
	public  boolean saveSpecialBetlistVectofile(){
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				filefolder.mkdir();
			}
			
			String filenametmp = "specialbetres"
					+ ".data";
			
			
			
			
			
			File file = new File("betdata/" +filenametmp);
			
			if(!file.exists()){
				System.out.println("create betdata/" + filenametmp);
				
				
				
				file.createNewFile();
			}
			
			BufferedWriter fwlocal = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));
			
			
			
			
			for(int i = 0; i < specialBetAdyDatas.size(); i++){
				
				BetAdyData item = specialBetAdyDatas.elementAt(i);
				
				String str = item.toString();
				
				fwlocal.append(str);
				fwlocal.newLine();
				fwlocal.flush();

			}
			
			fwlocal.close();
			
			
			
			return true;
			
			
		}catch(Exception e){
			e.printStackTrace();			
			return false;
		}
	}
	
	
	
	public  boolean saveSpecialBetlogVectofile(){
		
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				filefolder.mkdir();
			}
			
			String filenametmp = "specialbetlog"
					+ ".data";
			
			
			
			
			
			File file = new File("betdata/" +filenametmp);
			
			if(!file.exists()){
				System.out.println("create betdata/" + filenametmp);
				
				
				
				file.createNewFile();
			}
			
			BufferedWriter fwlocal = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));
			
			
			
			
			for(int i = 0; i < specialBetLogDatas.size(); i++){
				
				BetAdyData item = specialBetLogDatas.elementAt(i);
				
				String str = item.toString();
				
				fwlocal.append(str);
				fwlocal.newLine();
				fwlocal.flush();

			}
			
			fwlocal.close();
			
			
			
			return true;
			
			
		}catch(Exception e){
			e.printStackTrace();			
			return false;
		}
	}
	
	
	
	public  boolean saveBetLogVectofile(){
		try{
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
			
			Calendar currentTime = Calendar.getInstance();
			
			String folder = "";
			
			File filefolder = new File("betdata/");
			
			if(!filefolder.exists()){
				filefolder.mkdir();
			}
			
//			if(currentTime.get(Calendar.HOUR_OF_DAY) >= 12){
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}else{
//				currentTime.add(Calendar.DAY_OF_MONTH, -1);
//				folder += dfmin.format(currentTime.getTimeInMillis());
//			}
			
//			filefolder = new File("betdata/" + folder + "/");
//			
//			if(!filefolder.exists()){
//				filefolder.mkdir();
//			}
			
			String filenametmp = "betlog"
					+ ".data";
			
			
			
			
			
			File file = new File("betdata/" +filenametmp);
			
			if(!file.exists()){
				System.out.println("create betdata/" + filenametmp);
				
				
				
				file.createNewFile();
			}
			
			BufferedWriter fwlocal = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));
			
			
			
			
			for(int i = 0; i < betLogDatas.size(); i++){
				
				BetAdyData item = betLogDatas.elementAt(i);
				
				String str = item.toString();
				
				fwlocal.append(str);
				fwlocal.newLine();
				fwlocal.flush();

			}
			
			fwlocal.close();
			
			
			
			return true;
			
			
		}catch(Exception e){
			e.printStackTrace();
			
			
			
			
			return false;
		}
	}
	
	
	
	
	public void updateBetCentralTable(Vector<SendData> senddatas) {
		
		BetClient.mainWnd.updateBetCentralTable(senddatas);
		
	}
	
	public BetCentralManager() {
		hgmanager = new HGManager();
		hgmanager.init();
		
		ps38manager = new PS38Manager();
		ps38manager.init();
		
		isnManager = new ISNManager();
		isnManager.init();
		
//		recoverBetlistVecfromefile();
//		
//		recoverBetLogVecfromfile();
		
	}
	
	public String getOutlineData() {
		return isnManager.getOutlineData()
				;
	}
	
	public String getPS38OutlineData(String count) {
		return ps38manager.getOutlineData(count)
				;
	}
	
	public String getDetailsData(String datetime) {
		return isnManager.getDetailsData(datetime);
	}
	
	public String getPS38DetailsData(String datetime) {
		return ps38manager.getDetailsData(datetime);
	}
	
	public String getinUsedAccountName() {
		return hgmanager.getinUsedAccountName();
	}
	
	public void useNextAccount() {
		hgmanager.useNextAccount();
	}
	
//	public Vector<String> getaccountnames(){
//		return hgmanager.getaccountnames();
//	}
	
	//HG
	public void keepHGonline() {
		hgmanager.login();
		hgmanager.checkIsOnline();
	};
	
	
	
	public Map<String, String> getInplaybetScores(){
		
		if(hgmanager.getStatuscode() == 1) {
			return hgmanager.getInplaybetScores();
		}
		return null;
		
	}
	
	
	
	
	public Map<String, String> updateRatio(String gid, String type, String gnum, String strong, String rtype, String wtype){
		
		if(hgmanager.getStatuscode() == 1) {
			return hgmanager.updateRatio(gid, type, gnum, strong, rtype, wtype);
		}
		return null;
		
	}
	
	
	public Map<String, String> updateSpecialAccountRatio(String gid, String type, String gnum, String strong, String rtype, String wtype){
		
		if(hgmanager.getSpecialAccountStatuscode() == 1) {
			return hgmanager.updateSpecialAccountRatio(gid, type, gnum, strong, rtype, wtype);
		}
		return null;
		
	}
	
	
	
	public Map<String,String> hgdobet(String betParam, int gold) {
		
		if(hgmanager.getStatuscode()==1) {
			return hgmanager.dobet(betParam , gold);
		}
		return null;
	}
	
	public String isndobet(String homeTeam, String awayTeam, String updown, double ratio, int gold, Vector<Double> hgpankous) {
		
		if(isnManager.getStatuscode()==1) {
			return isnManager.dobet(homeTeam, awayTeam, updown, ratio, gold, hgpankous);
		}
		return null;
	}
	
	public String isndobetdxq(String homeTeam, String awayTeam, String updown, double ratio, int gold, Vector<Double> hgpankous) {
		
		if(isnManager.getStatuscode()==1) {
			return isnManager.dobetdxq(homeTeam, awayTeam, updown, ratio, gold, hgpankous);
		}
		return null;
	}
	
	public JSONObject getISNEvent() {
		if(isnManager.getStatuscode()==1) {
			return isnManager.getISNEvent();
		}
		return null;
	}

	
	public Map<String,String> hgdospecialbet(String betParam, int gold) {
		
		if(hgmanager.getSpecialAccountStatuscode()==1) {
			return hgmanager.dobetSpecialaccount(betParam, gold);
		}
		return null;
	}

	
	public String getHGBetAccount() {
		return hgmanager.getHGBetAccount();
	}
	
	public String getISNBetAccount() {
		return isnManager.getISNbetAccount();
	}
	
	public String getPS38BetAccount() {
		return ps38manager.getPS38BetAccount();
	}
	
	public Map<String, String> ps38dobet(Map<String, String> oddUpdres, int gold) {
		if(ps38manager.getStatuscode()==2) {
			return ps38manager.dobet(oddUpdres , gold);
		}
		return null;
	}
	
	
	public  String getEventStr(String homeTeam, String awayTeam){
		if(ps38manager.getStatuscode()==2) {
			return ps38manager.getEventStr(homeTeam, awayTeam);
		}
		return null;
	}
	
	public  Vector<Event> getMatches(String matchstr, String homeTeam, String awayTeam){
		if(ps38manager.getStatuscode()==2) {
			return ps38manager.getMatches(matchstr,homeTeam, awayTeam);
		}
		return null;
	}
	
	
	public Map<String, String> manualps38dobet(Map<String, String> oddUpdres, int gold) {
		if(ps38manager.getStatuscode()==2) {
			return ps38manager.manualdobet(oddUpdres , gold);
		}
		return null;
	}
	
	
	
	//PS38
	public void keepPS38online() {
		ps38manager.prepareLogin();
		ps38manager.getMainPage();
		ps38manager.login();
		ps38manager.getbalance();
	}
	
	//PS38
	public void keepISNonline() {
		
		isnManager.login();
		isnManager.getbalance();
	}
	
	
	public Map<String, String>  updatePS38Ratio(String betid, String eventid, String bettype, String typedetail, String pankou) {
		
		if(ps38manager.getStatuscode() == 2) {
			return ps38manager.updatePS38Ratio(betid, eventid, bettype, typedetail, pankou);
		}
		
		return null;
	}
	
	
	
	public void updatePS38StatusCode(int i) {
		ps38manager.updateStatuscode(i);
	}
	
	
	
	public Map<String, String>  manualRebetUpdatePS38Ratio(String betid, String eventid, String bettype, String typedetail, String pankou) {
		
		if(ps38manager.getStatuscode() == 2) {
			return ps38manager.manualRebetUpdatePS38Ratio(betid, eventid, bettype, typedetail, pankou);
		}
		
		return null;
	}
	
	
	public Event grabOneEvent(String eventidarg, String pankou, String typedetail) {
		if(ps38manager.getStatuscode() == 2) {
			return ps38manager.grabOneEvent(eventidarg, pankou, typedetail);
		}
		
		return null; 
	}
	
	
	
	public void updatehgBetLogData() {
		try {
			
			
			if(System.currentTimeMillis() - updateBetlogTime < 8*1000) {
				return;
			}
			
			
			updateBetlogTime = System.currentTimeMillis();
			
			
			boolean needToUpdate = false;
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			
			String date = df.format(System.currentTimeMillis());
			
			SimpleDateFormat dfSec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			
			
			
			
			for(int i = 0; i < betLogDatas.size(); i++) {
				
				
				
				BetAdyData bd = betLogDatas.elementAt(i);
				
				if(i != 0) {
					String time = date + " " + bd.currenttime;
					
					Long passtime = (System.currentTimeMillis() - dfSec.parse(time).getTime());
					
					if(passtime < 0 || passtime > 60*5 * 1000) {
						continue;
					}
					
				}
				
				
				if(bd.hgbetres.equals("0")) {
					needToUpdate = true;
					break;
				}
			}
			
			if(needToUpdate) {
				hgmanager.updatehgBetLogData(betLogDatas);
				
				BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
				
				saveBetlistVectofile();
				
				
				BetClient.mainWnd.updateBetLogTable(betLogDatas);
				
				saveBetLogVectofile();
				
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		

		
		
	}
	
	
	
	
	
	public void updatehgSpecialBetLogData() {
		
		
		try {

			if(System.currentTimeMillis() - updateSpecialBetlogTime < 8*1000) {
				return;
			}
			
			
			updateSpecialBetlogTime = System.currentTimeMillis();
			
			
			boolean needToUpdate = false;
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			
			String date = df.format(System.currentTimeMillis());
			
			SimpleDateFormat dfSec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			
			
			
			
			for(int i = 0; i < specialBetLogDatas.size(); i++) {
				
				BetAdyData bd = specialBetLogDatas.elementAt(i);
				
				if(i != 0) {
					String time = date + " " + bd.currenttime;
					
					Long passtime = (System.currentTimeMillis() - dfSec.parse(time).getTime());
					

					
					if(passtime < 0 || passtime > 60*5 * 1000) {
						continue;
					}
				}
				
				if(bd.hgbetres.equals("0")) {
					needToUpdate = true;
					break;
				}
			}
			
			if(needToUpdate) {
				
				isnManager.updatehgSpecialAccountBetLogData(specialBetLogDatas);
				
				BetClient.mainWnd.updateSpecialBetLogTable(specialBetLogDatas);
				
				BetClient.mainWnd.updateSpecialBetAdyTable(specialBetAdyDatas);
				
				saveSpecialBetlistVectofile();
				

				
				saveSpecialBetlogVectofile();
				
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		

		
		
	}
	
	
	
	public void udpateps38BetLogData() {
		
		try{
			
			
			if(System.currentTimeMillis() - updateps38BetlogTime < 8*1000 || BetClient.isInbet == true) {
				return;
			}
			
			
			updateps38BetlogTime = System.currentTimeMillis();
			
			boolean needToUpdate = false;
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			
			String date = df.format(System.currentTimeMillis());
			
			SimpleDateFormat dfSec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			

			
			for(int i = 0; i < betLogDatas.size(); i++) {
				
				
				
				BetAdyData bd = betLogDatas.elementAt(i);
				
				if(i != 0) {
					String time = date + " " + bd.currenttime;
					
					Long passtime = (System.currentTimeMillis() - dfSec.parse(time).getTime());
					
					if(passtime < 0 || passtime > 60*5 * 1000) {
						continue;
					}
					
				}
				
				
				if(bd.ps38betres.equals("0")) {
					needToUpdate = true;
					break;
				}
			}
			
			if(needToUpdate) {
				ps38manager.updateps38BetLogData(betLogDatas);
				
				
				BetClient.mainWnd.updateBetAdyTable(betAdyDatas);
				
				saveBetlistVectofile();
				
				
				BetClient.mainWnd.updateBetLogTable(betLogDatas);
				
				saveBetLogVectofile();
				
			}
			
			
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		
	}


	public void checkIllegalBet() {
		try {
			
			if(System.currentTimeMillis() - checkIllegalTime < 60*1000 || BetClient.hasIllegalBet == true) {
				return;
			}
			
			checkIllegalTime = System.currentTimeMillis();
			
			hgmanager.checkIllegalBet();
			
			//hgmanager.getRedCard();

		}catch(Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
	public void checkSpecialIllegalBet() {
		try {
			
			if(System.currentTimeMillis() - checkSpecialIllegalTime < 60*1000 || BetClient.hasSpecialIllegalBet == true) {
				return;
			}
			
			checkSpecialIllegalTime = System.currentTimeMillis();
			
			hgmanager.checkSpecialIllegalBet();

		}catch(Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
	public String getAccounttype() {
		if(hgmanager.getStatuscode() == 1) {
			return hgmanager.getAccounttype();
		}
		return "3";
	}

	public Vector<HGEvent> getSpecialAccountInplaybet() {
		if(hgmanager.getSpecialAccountStatuscode() == 1) {
			return hgmanager.getSpecialAccountInplaybet();
		}
		return null;
	}


	
	
	
	
}
